/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SwingUI.java
 *
 * Created on May 3, 2010, 4:44:10 PM
 */

package UI;


import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import static org.junit.Assert.*;
import java.awt.*;
import javax.swing.*;
import Core.*;
import Data.*;
import Rendering.*;
import Rendering.Utils.*;
//import java.util.Map;
import Utils.LocationFinder.AddressFinder;
import java.util.HashMap;
import java.util.Iterator;

import java.util.Set;
import java.util.SortedMap;
import java.util.Collections.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyListener;
import java.awt.event.AWTEventListener;
import java.awt.Color;
import javax.swing.BoxLayout;
import javax.swing.border.*;
import Utils.PathFinder.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;


/**
 *
 * @author Alina Beju
 */
public class SwingUI extends javax.swing.JFrame  {
     class TestProvider implements IMapProvider {
    public      ArrayList<Node> nodes;
    public    ArrayList<Street> streets;
    public ArrayList<Link> links;
    public int startid;


        void AddLink(Node a, Node b, Street street, double dist, int s, int e) {
            Link l = new Link(ObjectId.NewId(), b.Id(), street.Id());
            l.SetDistance(dist);
            l.SetStartPoint(s);
            l.SetEndPoint(e);
            a.AddLink(l);
            links.add(l);
        }

        public TestProvider() {
            nodes = new ArrayList<Node>();
            streets = new ArrayList<Street>();
            links = new ArrayList<Link>();

           
            /*for(int i = 0; i < 10; i++) {
                nodes.add(new Node(ObjectId.NewId(), new Coordinates(0, 0)));
            }*/
// creare noduri:
            nodes.add(new Node(ObjectId.NewId(), new Coordinates(0, 0)));
            startid = nodes.get(nodes.size() - 1).Id().Id();
            nodes.add(new Node(ObjectId.NewId(), new Coordinates(0, 1)));
            nodes.add(new Node(ObjectId.NewId(), new Coordinates(0, 2)));
            nodes.add(new Node(ObjectId.NewId(), new Coordinates(0, 3)));
            nodes.add(new Node(ObjectId.NewId(), new Coordinates(1, 0)));
            nodes.add(new Node(ObjectId.NewId(), new Coordinates(1, 1)));
            nodes.add(new Node(ObjectId.NewId(), new Coordinates(1, 2)));
            nodes.add(new Node(ObjectId.NewId(), new Coordinates(1, 3)));
            nodes.add(new Node(ObjectId.NewId(), new Coordinates(2, 0)));
            nodes.add(new Node(ObjectId.NewId(), new Coordinates(2, 1)));


            //Adauga strazi (orizontal)
              Street s0 = new Street(ObjectId.NewId(), StreetType.Street,
                            "str0", nodes.get(0),nodes.get(3));
                for(int j = 0; j < 5; j++)
                    s0.AddCoordinate(new Coordinates(0, j));
               streets.add(s0);

               Street s1 = new Street(ObjectId.NewId(), StreetType.Street
                         ,"str1", nodes.get(4),nodes.get(7));
                for(int j = 0; j < 5; j++)
                    s1.AddCoordinate(new Coordinates(1, j));
                streets.add(s1);

                Street s2 = new Street(ObjectId.NewId(), StreetType.Street,
                                "str2", nodes.get(8),nodes.get(9));
                for(int j = 0; j < 5; j++)
                    s2.AddCoordinate(new Coordinates(2, j));

                streets.add(s2);

                //Adauga strazi verticale;

                Street s3 = new Street(ObjectId.NewId(), StreetType.Street,
                                "str3", nodes.get(0),nodes.get(8));
                for(int j = 0; j < 5; j++)
                    s3.AddCoordinate(new Coordinates(j, 0));

                streets.add(s3);

                 for(int i = 0; i < 3; i++) {
                Street s = new Street(ObjectId.NewId(), StreetType.Street);
                //,"str", nodes.get(0),nodes.get(3));
                for(int j = 0; j < 6; j++) {
                    s.AddCoordinate(new Coordinates(i, i));
                }

                streets.add(s);
            }


            // Adauga link-uri (orizontal).
            AddLink(nodes.get(0), nodes.get(1), streets.get(0), 10, 0, 1);
            AddLink(nodes.get(1), nodes.get(2), streets.get(0), 20, 1, 2);
            AddLink(nodes.get(2), nodes.get(3), streets.get(0), 10, 2, 3);

            //Linkuri bidirectionale
            AddLink(nodes.get(1), nodes.get(0), streets.get(0), 10, 1, 0);
            AddLink(nodes.get(2), nodes.get(1), streets.get(0), 20, 2, 1);
            AddLink(nodes.get(3), nodes.get(2), streets.get(0), 10, 3, 2);


            AddLink(nodes.get(4), nodes.get(5), streets.get(1), 3, 0, 1);
            AddLink(nodes.get(5), nodes.get(6), streets.get(1), 2, 1, 2);
            AddLink(nodes.get(6), nodes.get(7), streets.get(1), 1, 2, 3);

            AddLink(nodes.get(8), nodes.get(9), streets.get(2), 2, 0, 1);

            // Vertical.
            AddLink(nodes.get(0), nodes.get(4), streets.get(3), 2, 0, 1);
            AddLink(nodes.get(4), nodes.get(8), streets.get(3), 5, 1, 2);

            AddLink(nodes.get(1), nodes.get(5), streets.get(4), 30, 0, 1);

            AddLink(nodes.get(2), nodes.get(6), streets.get(5), 4, 0, 1);
        }



        public String Name() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public int ZoomLevels() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public Region MapBounds() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public Region2D MapBounds(int zoomLevel) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public IProjection Projection() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public int LayerCount() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public boolean HasLayer(LayerType layerType) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public ILayer GetLayer(ObjectId layerId) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public Iterator<ILayer> GetLayerIterator() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public double TileSize() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public int TileCount(int zoomLevel) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public TileInfo GetTile(Core.Point point, int zoomLevel) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public void GetTiles(Region2D region, int zoomLevel, java.util.List<TileInfo> list) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public Image LoadTile(ObjectId tileId) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public int NodeNumber() {
            return nodes.size();
        }

        public Iterator<Node> GetNodeIterator() {
            return nodes.iterator();
        }

        public Node GetNode(ObjectId nodeID) {
            for(int i = 0; i < nodes.size(); i++) {
                Node n = nodes.get(i);
                if(n.Id().equals(nodeID)) {
                    return n;
                }
            }

            throw new RuntimeException("Nu trebuie sa se ajunga aici!!!");
        }

        public int StreetCount() {
            return streets.size();
        }

        public Iterator<Street> GetStreetIterator() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public Street GetStreet(ObjectId streetID) {
            for(int i = 0; i < streets.size(); i++) {
                Street s = streets.get(i);
                if(s.Id().equals(streetID)) {
                    return s;
                }
            }

            throw new RuntimeException("Nu trebuie sa se ajunga aici!!!");
        }

        public Core.Color StreetColor(StreetType streetType) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public int MarkerCount(ObjectId layerID) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public Iterator<Marker> GetMarkerIterator(ObjectId layerID) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public Marker GetMarker(ObjectId markerID, ObjectId layerID) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public Image LoadMarkerIcon(ObjectId layerID) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public void Load(String location) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public void Save(String location) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
        
    }

    PanelViewer pw;
    JPanel menuPanel_, layersPanel_;
    Route route;
    AddressFinder finder_;
   // FileMapProvider fileMapProvider_;



    HashMap<JCheckBox, ILayer> layerMap_ = new HashMap<JCheckBox, ILayer>();
    Boolean selectat = true;
    AutoCompleteBox acBox, acBox2;
    JButton searchButton;
  
    /** Creates new form SwingUI */
    public SwingUI() {

        initComponents();
        pw = new PanelViewer();
         
        Container contentPane = this.getContentPane();

        BorderLayout layout = new BorderLayout();
        contentPane.setLayout(layout);
       

          /* Panel-ul pentru meniu */
        menuPanel_ = new JPanel();
        menuPanel_.setPreferredSize(new Dimension(200,600));
        menuPanel_.setBackground(new Color(66, 90, 87));

          /* Panel-ul pentru Layers */
        layersPanel_ = new JPanel();
        layersPanel_.setPreferredSize(new Dimension(200,200));
        layersPanel_.setBackground(new Color(218, 248, 244));

          /* Panel-ul pentru Road */
        directionsPanel_.setPreferredSize(new Dimension(200,400));
        directionsPanel_.setMaximumSize(new Dimension(200,400));
        directionsPanel_.setBackground(new Color(218, 248, 244));

        BoxLayout boxlayout = new BoxLayout(comboBoxPanel_, BoxLayout.PAGE_AXIS);
        comboBoxPanel_.setLayout(boxlayout);
        comboBoxPanel_.setPreferredSize(new Dimension(200,180));
        comboBoxPanel_.setMaximumSize(new Dimension(200,180));
        comboBoxPanel_.setBackground(new Color(218, 248, 244));

        comboBoxPanel_.add(Box.createVerticalStrut(10));

        JLabel label = new JLabel("From: ");
        label.setMaximumSize(new Dimension(180, 10));
        label.setAlignmentX(Component.LEFT_ALIGNMENT);
        comboBoxPanel_.add(label);

        comboBoxPanel_.add(Box.createVerticalStrut(10));

        acBox = new AutoCompleteBox();
        acBox.setPreferredSize(new Dimension(180, 20));
        acBox.setMaximumSize(new Dimension(180, 20));
        acBox.setAlignmentX(Component.LEFT_ALIGNMENT);
        

        comboBoxPanel_.add(acBox);

        comboBoxPanel_.add(Box.createVerticalStrut(10));

        JLabel label2 = new JLabel("To: ");
        label2.setMaximumSize(new Dimension(180, 10));
        label2.setAlignmentX(Component.LEFT_ALIGNMENT);
        comboBoxPanel_.add(label2);

        comboBoxPanel_.add(Box.createVerticalStrut(10));

        acBox2 = new AutoCompleteBox();
        acBox2.setPreferredSize(new Dimension(180, 20));
        acBox2.setMaximumSize(new Dimension(180, 20));
        acBox2.setAlignmentX(Component.LEFT_ALIGNMENT);

        comboBoxPanel_.add(acBox2);

        comboBoxPanel_.add(Box.createVerticalStrut(10));

        
        searchButton = new JButton("Search");
        searchButton.addActionListener(
            new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                JButton B = (JButton)e.getSource();
                if(B == searchButton)
                {
                    ArrayList<Step> newlist = new ArrayList<Step>();
                    String location1 = acBox.getSelectedItem().toString();
                    String location2 = acBox2.getSelectedItem().toString();

                    Street street1 = finder_.FindAddress(location1);
                    Street street2 = finder_.FindAddress(location2);

                    if  ((street1 !=null)&&(street2!=null))
                    {
                        Node node1 = street1.StartNode();
                        Node node2 = street2.StartNode();

                        TestProvider t = new TestProvider();
                        route = new DikstraPF(t).RoutePath(new ObjectId(t.startid), new ObjectId(t.startid + 9));
                        ShowDirections(t);

                        System.out.println(route);
                    }
                else if(street1==null){}
                }
            }
        }
        );

        searchButton.setPreferredSize(new Dimension(100, 25));
        searchButton.setMaximumSize(new Dimension(100, 25));
        searchButton.setAlignmentX(Component.LEFT_ALIGNMENT);

        comboBoxPanel_.add(searchButton);
            
        menuPanel_.add(layersPanel_);
        menuPanel_.add(directionsPanel_);
        

        contentPane.add(toolBar, BorderLayout.PAGE_START);
        contentPane.add(menuPanel_, BorderLayout.WEST);
        contentPane.add(pw, BorderLayout.CENTER);
      
 
    }


    public void ShowCheckBoxes()
    {
          /* Panel-ul layerHead_ */
        JPanel layerHead_ = new JPanel();
        layerHead_.setBackground(new java.awt.Color(241, 250, 249));
        layerHead_.setMaximumSize(new Dimension(200, 30));

         BorderLayout layerHeadLayout = new BorderLayout();
         layerHead_.setLayout(layerHeadLayout);

          /* Label-ul Layers  */
        JLabel layersLabel_ = new JLabel("Layers");
        layersLabel_.setFont(new java.awt.Font("Tahoma Bold", 0, 12));
        layerHead_.add(layersLabel_, BorderLayout.WEST);
        layersPanel_.add(layerHead_);
        
          /* GroupLayout-ul cu checkbox-uri */
        GroupLayout childPanel1Layout = new GroupLayout(layersPanel_);
        layersPanel_.setLayout(childPanel1Layout);
        childPanel1Layout.getAutoCreateGaps();

        GroupLayout.ParallelGroup childPanel1Par = childPanel1Layout
                    .createParallelGroup()
                    .addComponent(layerHead_);

        GroupLayout.SequentialGroup childPanel1Seq = childPanel1Layout
                    .createSequentialGroup()
                    .addComponent(layerHead_);

        IMapProvider provider = pw.Provider();
       // FileMapProvider provider = pw.Provider();
        Iterator<ILayer> iterator = provider.GetLayerIterator();

        while(iterator.hasNext())
        {
            ILayer current_layer = iterator.next();
            if(current_layer.Type() == LayerType.Image) continue;

            JCheckBox c1 = new JCheckBox();
            c1.setBackground(new Color(218, 248, 244));
            layerMap_.put(c1,current_layer);

            c1.setSelected(true);
            c1.setText(current_layer.Name());

            c1.addItemListener(
            new ItemListener() {
                public void itemStateChanged(ItemEvent e)
                {
                    //daca JCheckBox e selectat, va fi true, daca nu e selectat, va fi false
                     selectat = (e.getStateChange() == ItemEvent.SELECTED);

                     if(selectat) {
                        //daca e selectat, afiseaza din layerMap_ layer-ul corespunzator JCheckBox-ului
                        pw.ShowLayer(layerMap_.get((JCheckBox)e.getItem()));
                     }
                     else {
                         //daca nu e selectat, ascunde din layerMap_ layer-ul corespunzator JCheckBox-ului
                         pw.HideLayer(layerMap_.get((JCheckBox)e.getItem()));
                     }
                }

                 });

           childPanel1Par = childPanel1Par.addComponent(c1);
           childPanel1Layout.setHorizontalGroup(
           childPanel1Layout.createParallelGroup().addGroup(childPanel1Par));

           childPanel1Seq.addComponent(c1);

           childPanel1Layout.setVerticalGroup(
           childPanel1Layout.createParallelGroup().addGroup(childPanel1Seq));
        }
    }
    
    public void ShowDirections(IMapProvider provider)
    {
         streetsPanel_.setLayout(new BoxLayout(streetsPanel_, BoxLayout.PAGE_AXIS));
         streetsPanel_.removeAll();
         
        Iterator<Step> iterator = route.StepList().iterator();
        int i=1;
        while(iterator.hasNext())
        {
            Step step = (Step)iterator.next();

            JPanel street = new JPanel();
            street.setLayout(new BoxLayout(street, BoxLayout.PAGE_AXIS));
            street.setBackground(new Color(141,213,211));
            street.setBorder(BorderFactory.createLineBorder(new Color(134,177,171), 1));
            street.setMaximumSize(new Dimension(190,40));

            JLabel streetLabel_ = new JLabel();
            JLabel distanceLabel_ = new JLabel();
            streetLabel_.setFont(new Font("Tahoma",0,11));
            distanceLabel_.setFont(new Font("Tahoma",0,11));
            streetLabel_.setText(i+"." + step.Direction().toString());

            Street s = provider.GetStreet(step.StreetId());
                streetLabel_.setText
                        (streetLabel_.getText() + " on " + s.Name());
                distanceLabel_.setText(" Distance: " + step.Distance() + " km");
                street.add(streetLabel_);
                street.add(distanceLabel_);
                streetsPanel_.add(street,BorderLayout.WEST);
                System.out.println(streetLabel_.getText() + distanceLabel_.getText());
                streetsPanel_.revalidate();
            i++;
        }
 
    
    }



    /* This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        toolBar = new javax.swing.JToolBar();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        directionsPanel_ = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        verticalPane_ = new javax.swing.JScrollPane();
        streetsPanel_ = new javax.swing.JPanel();
        comboBoxPanel_ = new javax.swing.JPanel();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        openMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        saveAsMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        cutMenuItem = new javax.swing.JMenuItem();
        copyMenuItem = new javax.swing.JMenuItem();
        pasteMenuItem = new javax.swing.JMenuItem();
        deleteMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        contentsMenuItem = new javax.swing.JMenuItem();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Map Viewer");
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                formMousePressed(evt);
            }
        });
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });
        addWindowStateListener(new java.awt.event.WindowStateListener() {
            public void windowStateChanged(java.awt.event.WindowEvent evt) {
                formWindowStateChanged(evt);
            }
        });

        toolBar.setFloatable(false);
        toolBar.setRollover(true);
        toolBar.setName("toolBar"); // NOI18N

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI/open.png"))); // NOI18N
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setName("jButton4"); // NOI18N
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        toolBar.add(jButton4);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI/save.png"))); // NOI18N
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.setName("jButton5"); // NOI18N
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBar.add(jButton5);

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI/edit.png"))); // NOI18N
        jButton6.setFocusable(false);
        jButton6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton6.setName("jButton6"); // NOI18N
        jButton6.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StreetEditHandler(evt);
            }
        });
        toolBar.add(jButton6);

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI/edit.png"))); // NOI18N
        jButton7.setFocusable(false);
        jButton7.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton7.setName("jButton7"); // NOI18N
        jButton7.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7StreetEditHandler(evt);
            }
        });
        toolBar.add(jButton7);

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UI/edit.png"))); // NOI18N
        jButton8.setFocusable(false);
        jButton8.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton8.setName("jButton8"); // NOI18N
        jButton8.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8StreetEditHandler(evt);
            }
        });
        toolBar.add(jButton8);

        directionsPanel_.setMaximumSize(new java.awt.Dimension(200, 300));
        directionsPanel_.setName("directionsPanel_"); // NOI18N

        jPanel2.setBackground(new java.awt.Color(241, 250, 249));
        jPanel2.setName("jPanel2"); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel1.setText("Directions");
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addContainerGap(149, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
        );

        verticalPane_.setName("verticalPane_"); // NOI18N

        streetsPanel_.setName("streetsPanel_"); // NOI18N

        javax.swing.GroupLayout streetsPanel_Layout = new javax.swing.GroupLayout(streetsPanel_);
        streetsPanel_.setLayout(streetsPanel_Layout);
        streetsPanel_Layout.setHorizontalGroup(
            streetsPanel_Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 220, Short.MAX_VALUE)
        );
        streetsPanel_Layout.setVerticalGroup(
            streetsPanel_Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 131, Short.MAX_VALUE)
        );

        verticalPane_.setViewportView(streetsPanel_);

        comboBoxPanel_.setName("comboBoxPanel_"); // NOI18N

        javax.swing.GroupLayout comboBoxPanel_Layout = new javax.swing.GroupLayout(comboBoxPanel_);
        comboBoxPanel_.setLayout(comboBoxPanel_Layout);
        comboBoxPanel_Layout.setHorizontalGroup(
            comboBoxPanel_Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 190, Short.MAX_VALUE)
        );
        comboBoxPanel_Layout.setVerticalGroup(
            comboBoxPanel_Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 91, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout directionsPanel_Layout = new javax.swing.GroupLayout(directionsPanel_);
        directionsPanel_.setLayout(directionsPanel_Layout);
        directionsPanel_Layout.setHorizontalGroup(
            directionsPanel_Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(directionsPanel_Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(comboBoxPanel_, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(directionsPanel_Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(verticalPane_, javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE)
                .addContainerGap())
        );
        directionsPanel_Layout.setVerticalGroup(
            directionsPanel_Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(directionsPanel_Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(comboBoxPanel_, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(verticalPane_, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );

        fileMenu.setText("File");

        openMenuItem.setText("Open");
        fileMenu.add(openMenuItem);

        saveMenuItem.setText("Save");
        fileMenu.add(saveMenuItem);

        saveAsMenuItem.setText("Save As ...");
        fileMenu.add(saveAsMenuItem);

        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        editMenu.setText("Edit");

        cutMenuItem.setText("Cut");
        editMenu.add(cutMenuItem);

        copyMenuItem.setText("Copy");
        editMenu.add(copyMenuItem);

        pasteMenuItem.setText("Paste");
        editMenu.add(pasteMenuItem);

        deleteMenuItem.setText("Delete");
        editMenu.add(deleteMenuItem);

        menuBar.add(editMenu);

        helpMenu.setText("Help");

        contentsMenuItem.setText("Contents");
        helpMenu.add(contentsMenuItem);

        aboutMenuItem.setText("About");
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(directionsPanel_, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(714, 714, 714)
                .addComponent(toolBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(315, 315, 315)
                .addComponent(directionsPanel_, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated

    }//GEN-LAST:event_formWindowActivated

    private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed
        // TODO add your handling code here:
    }//GEN-LAST:event_formMousePressed

    private void StreetEditHandler(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StreetEditHandler
        pw.RemoveEditors();
        pw.CreateStreetEditor();
    }//GEN-LAST:event_StreetEditHandler

    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
     
        int width, height;
        width = evt.getComponent().getSize().width - 150;
        height = evt.getComponent().getSize().height - 100;
        pw.SeteazaMarimea(width,height);
        directionsPanel_.setPreferredSize(new Dimension(200, (evt.getComponent().getSize().height - 300) ));
        directionsPanel_.revalidate();
        
        
    }//GEN-LAST:event_formComponentResized

    private void formWindowStateChanged(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowStateChanged

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        JFileChooser openFile_ = new JFileChooser();
        FileMapProvider fileMapProvider = new FileMapProvider();
        int returnVal = openFile_.showOpenDialog(comboBoxPanel_);
        if(returnVal == JFileChooser.APPROVE_OPTION) 
        {
            try
            {
              fileMapProvider.Load(openFile_.getSelectedFile().getPath());
              pw.setProvider(fileMapProvider);
              pw.Viewer().LoadMap(fileMapProvider);

              acBox.SetFinder(new AddressFinder(pw.Provider()));
              acBox2.SetFinder(new AddressFinder(pw.Provider()));
              ShowCheckBoxes();
           // pw.Provider().Load("C:\\test.map");
            //fileMapProvider_.Load(openFile_.getSelectedFile().getPath());
            }
            catch(Exception e)
            {
            
            }
           // pw.Viewer().LoadMap(null);
       System.out.println("You chose to open this file: " + openFile_.getSelectedFile().getPath().toString());
        }

    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton7StreetEditHandler(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7StreetEditHandler
       
        pw.HideEditors();
        pw.CreateNodeEditor();
    }//GEN-LAST:event_jButton7StreetEditHandler

    private void jButton8StreetEditHandler(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8StreetEditHandler
        pw.HideEditors();
        pw.CreateMarkerEditor();
        
    }//GEN-LAST:event_jButton8StreetEditHandler

    @Override
    public Container getContentPane() {
        return super.getContentPane();
    }
    /**
    * @param args the command line arguments
    */
   public static void main(String args[]) {
       try {
        UIManager.setLookAndFeel(
        UIManager.getSystemLookAndFeelClassName());
        }

       catch (Exception e) {
       
       }


        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SwingUI().setVisible(true);
            }
        });
    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JPanel comboBoxPanel_;
    private javax.swing.JMenuItem contentsMenuItem;
    private javax.swing.JMenuItem copyMenuItem;
    private javax.swing.JMenuItem cutMenuItem;
    private javax.swing.JMenuItem deleteMenuItem;
    private javax.swing.JPanel directionsPanel_;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JMenuItem pasteMenuItem;
    private javax.swing.JMenuItem saveAsMenuItem;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JPanel streetsPanel_;
    private javax.swing.JToolBar toolBar;
    private javax.swing.JScrollPane verticalPane_;
    // End of variables declaration//GEN-END:variables

}

       
   


   
